package com.fin.zw.intelligentbot.controller.api;

import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.model.ResulteWraper;
import com.fin.zw.intelligentbot.model.base.Robot;
import com.fin.zw.intelligentbot.model.request.RobotInfoRequest;
import com.fin.zw.intelligentbot.model.response.RobotInfoResponse;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.RobotInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/robot")
@Api(value = "机器人信息", description = "机器人信息")
public class RobotController {
    @Autowired
    private RobotInfoService robotService;

    @GetMapping("/fetch")
    @ApiOperation(value = "查询机器人信息", notes = "查询机器人信息")
    public ResponseEntity<ResulteWraper> fetch(RobotInfoRequest condition, @ApiIgnore @CurrentUser SessionModel sessionModel)
    {
        ResulteWraper wraper = new ResulteWraper();
        List<Robot> robots = new ArrayList<>();
        List<RobotInfoResponse> robotInfos = this.robotService.fetch(condition,sessionModel);
        robotInfos.forEach(r->{
            Robot rob = new Robot();
            BeanUtils.copyProperties(r,rob);
            robots.add(rob);
        });
        wraper.setData(robots);
        return ResponseEntity.ok().body(wraper);
    }
}

